<template>
  <!-- 人气推荐的单个商品子组件 -->
  <div class="good-item" @click="gotoDetail">
    <img :src="item.pic" alt="" />
    <h6>{{ item.name }}</h6>
    <p>{{ item.characteristic }}</p>
    <span>{{ item.minPrice }}</span>
  </div>
</template>
<script>
import { useRouter } from "vue-router";
export default {
  props: {
    item: Object,
  },
  setup(props) {
    const router = useRouter();
    console.log(props.item.id);
    //setup的第一个参数就是拿props里的数据用的

    const gotoDetail = () => {
      //   router.push({ path: "/recommendDetail", query: { id: props.item.id } });
      //   router.push({ name: "recommendDetail", params: { id: props.item.id } });
      //路由的query传参和params传参

      router.push("/recommendDetail/" + props.item.id);
      //动态传参 在路由配置中要加上:id
    };
    return { gotoDetail };
  },
};
</script>
<style lang="scss">
.good-item {
  display: flex;
  flex-direction: column;
  img {
    width: 100%;
    height: 216px;
  }
  h6 {
    font-size: 14px;
    color: #000000;
    width: 144px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-weight: normal;
  }
  p {
    font-size: 12px;
    color: #b2b2b2;
    width: 144px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    margin-top: 8px;
  }
  span {
    font-size: 12px;
    color: #d00000;
    margin-top: 8px;
  }
}
</style>
